package cn.zyq.ykb.service.tk.impl;

import cn.zyq.ykb.beans.user.User;
import cn.zyq.ykb.system.common.BaseService;
import com.github.pagehelper.PageHelper;
import cn.zyq.ykb.system.ry.util.SecurityUtils;
import cn.zyq.ykb.mapper.tk.MenuFoodMapper;
import cn.zyq.ykb.beans.tk.MenuFood;
import cn.zyq.ykb.service.tk.MenuFoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.zyq.ykb.system.common.PageParam;
import com.github.pagehelper.PageInfo;


import java.time.LocalDateTime;
import java.util.UUID;
import java.util.List;

/**
 * 菜品食材Service业务层处理
 *
 * @author SystemAuth
 * @date 2023-10-20
 */
@Service
public class MenuFoodServiceImpl  extends BaseService implements MenuFoodService {

    @Autowired
    private MenuFoodMapper menuFoodMapper;

    /**
     * 查询菜品食材
     *
     * @param menuFoodID 菜品食材主键
     * @return 菜品食材
     */
    @Override
    public MenuFood selectMenuFoodByMenuFoodID(Integer menuFoodID) {
        MenuFood menuFood = menuFoodMapper.selectByPrimaryKey(menuFoodID);
        if (menuFood.getDeleted() == 1) {
            return null;
        }
        return menuFood;
    }

    /**
     * 查询菜品食材
     *
     * @param serviceID 业务ID
     * @return 菜品食材
     */
    @Override
    public MenuFood selectMenuFoodByServiceID(String serviceID) {
        MenuFood param = new MenuFood();
        param.setDeleted(0);
        param.setServiceID(serviceID);
        return this.menuFoodMapper.selectOne(param);
    }

    /**
     * 查询菜品食材列表
     *
     * @param pageParam
     * @return 菜品食材
     */
    @Override
    public PageInfo<MenuFood> selectMenuFoodList(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        pageParam.getKv().put("deleted", 0);
        List<MenuFood> list = this.menuFoodMapper.list(pageParam.getKv());
        return new PageInfo<>(list);
    }

    /**
     * 查询菜品食材列表
     *
     * @param pageParam
     * @return 菜品食材
     */
    @Override
    public List<MenuFood> selectMenuFoodAllList(PageParam pageParam) {
        pageParam.getKv().put("deleted", 0);
        return this.menuFoodMapper.list(pageParam.getKv());
    }
    /**
     * 新增菜品食材
     *
     * @param param 菜品食材
     * @return 结果
     */
    @Override
    public int insertMenuFood(MenuFood param) {
        this.setCreateBaseData(param, new User());
        return this.menuFoodMapper.insertSelective(param);
    }

    /**
     * 修改菜品食材
     *
     * @param param 菜品食材
     * @return 结果
     */
    @Override
    public int updateMenuFood(MenuFood param) {
        this.setUpdateBaseData(param, new User());
        return this.menuFoodMapper.updateByPrimaryKeySelective(param);
    }

    /**
     * 批量删除菜品食材
     *
     * @param menuFoodIDs 需要删除的菜品食材主键
     * @return 结果
     */
    @Override
    public int deleteMenuFoodByMenuFoodIDs(Integer[] menuFoodIDs) {
        int i = 0;
        for (Integer menuFoodID : menuFoodIDs) {
            i += this.deleteMenuFoodByMenuFoodID(menuFoodID);
        }
        return i;
    }

    /**
     * 删除菜品食材信息
     *
     * @param menuFoodID 菜品食材主键
     * @return 结果
     */
    @Override
    public int deleteMenuFoodByMenuFoodID(Integer menuFoodID) {
        MenuFood menuFood = this.selectMenuFoodByMenuFoodID(menuFoodID);
        if (menuFood == null) {
            return 0;
        } else {
            MenuFood storeInfo = new MenuFood();
            storeInfo.setMenuFoodID(menuFoodID);
            storeInfo.setDeleted(1);
            storeInfo.setUpdateTime(LocalDateTime.now());
            this.menuFoodMapper.updateByPrimaryKeySelective(storeInfo);
            return 1;
        }
    }
}
